package com.lufei4.chestnut.workspace;

import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lufei4.chestnut.R;
import com.lufei4.chestnut.workspace.adapter.H5TestBookAdapter;
import com.lufei4.chestnut.workspace.adapter.H5TestQuestionsAdapter;
import com.lufei4.chestnut.workspace.adapter.H5TestRightsAndInterestsAdapter;
import com.lufei4.chestnut.workspace.adapter.H5TestSetMealAdapter;
import com.lufei4.chestnut.workspace.adapter.SpacesItemDecoration;
import com.lufei4.chestnut.workspace.bean.BeanBook;
import com.lufei4.chestnut.workspace.bean.BeanInterests;
import com.lufei4.chestnut.workspace.bean.BeanQuestions;
import com.lufei4.chestnut.workspace.bean.BeanSetMeal;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: Chestnut
 * @Package: com.lufei4.chestnut.workspace
 * @ClassName: H5TestActivity
 * @Description: java类作用描述
 * @Author: liushijiang 15833013864@163.com
 * @CreateDate: 2021/1/13 20:46
 * @UpdateUser: 更新者：
 * @UpdateDate: 2021/1/13 20:46
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class H5TestActivity extends AppCompatActivity {
    @BindView(R.id.mRecyclerView_book)
    RecyclerView mRecyclerViewBook;//书
    @BindView(R.id.mRecyclerView_testQuestions)
    RecyclerView mRecyclerViewTestQuestions;//试卷
    @BindView(R.id.mRecyclerView_rightsAndInterests)
    RecyclerView mRecyclerViewRightsAndInterests;//权益
    @BindView(R.id.mRecyclerView_setMeal)
    RecyclerView mRecyclerViewSetMeal;//套餐
    @BindView(R.id.con_bg2)
    ConstraintLayout conBg2;
    @BindView(R.id.mScrollView)
    ScrollView mScrollView;
    @BindView(R.id.iv_close)
    ImageView ivClose;
    @BindView(R.id.tv_more)
    TextView tvMore;
    @BindView(R.id.tv_year198)
    TextView tvYear198;
    @BindView(R.id.tv_year1198)
    TextView tvYear1198;
    @BindView(R.id.tv_explanation)
    TextView tvExplanation;
    private H5TestBookAdapter mAdapter_book;
    private H5TestQuestionsAdapter mAdapter_questions;
    private H5TestRightsAndInterestsAdapter mAdapter_interests;
    private H5TestSetMealAdapter mAdapter_setMeal;
    private List<BeanBook> mData_book;
    private List<BeanQuestions> mData_questions;
    private List<BeanInterests> mData_interests;
    private List<BeanSetMeal> mData_setMeal;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_h5test);
        ButterKnife.bind(this);
        setRecyclerViewBook();
        setRecyclerViewTestQuestions();
        setRecyclerViewRightsAndInterests();
        setRecyclerViewSetMeal();
        setData();
        tvMore.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        tvMore.getPaint().setAntiAlias(true);//抗锯齿
        tvYear198.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); //中划线
        tvYear1198.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); //中划线

    }

    //90 114
    private void setRecyclerViewTestQuestions() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
        mRecyclerViewTestQuestions.setLayoutManager(linearLayoutManager);
        mRecyclerViewTestQuestions.addItemDecoration(new SpacesItemDecoration(6));
        mData_questions = new ArrayList<>();
        mAdapter_questions = new H5TestQuestionsAdapter(mData_questions);
        mRecyclerViewTestQuestions.setAdapter(mAdapter_questions);
    }

    private void setRecyclerViewRightsAndInterests() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
        mRecyclerViewRightsAndInterests.setLayoutManager(linearLayoutManager);
        mRecyclerViewRightsAndInterests.addItemDecoration(new SpacesItemDecoration(6));
        mData_interests = new ArrayList<>();
        mAdapter_interests = new H5TestRightsAndInterestsAdapter(mData_interests);
        mRecyclerViewRightsAndInterests.setAdapter(mAdapter_interests);
    }

    private void setData() {
        mData_book.add(new BeanBook(R.drawable.pic1, false));
        mData_book.add(new BeanBook(R.drawable.pic2, false));
        mData_book.add(new BeanBook(R.drawable.pic3, false));
        mData_book.add(new BeanBook(R.drawable.pic4, false));

        mData_questions.add(new BeanQuestions(R.drawable.pic5, false));
        mData_questions.add(new BeanQuestions(R.drawable.pic6, false));
        mData_questions.add(new BeanQuestions(R.drawable.pic7, false));
        mData_questions.add(new BeanQuestions(R.drawable.pic8, false));

        mData_interests.add(new BeanInterests("学习周报", R.drawable.icon2));
        mData_interests.add(new BeanInterests("VIP标识", R.drawable.icon3));
        mData_interests.add(new BeanInterests("VIP客服", R.drawable.icon4));
        mData_interests.add(new BeanInterests("学生档案", R.drawable.icon5));
        int size = 8;


        mData_setMeal.add(new BeanSetMeal("连续包年", 168, "原价¥198", 14, false));
        mData_setMeal.add(new BeanSetMeal("连续包月", 19, "原价¥25", 19, false));
        mData_setMeal.add(new BeanSetMeal("1个月", 25, "", 25, false));
        mData_setMeal.add(new BeanSetMeal("连续包季", 53, "原价¥25", 17.7, false));
        mData_setMeal.add(new BeanSetMeal("3个月", 68, "", 22.7, false));
        mData_setMeal.add(new BeanSetMeal("12个月", 198, "", 16.5, false));

        mAdapter_questions.notifyDataSetChanged();
        mAdapter_book.notifyDataSetChanged();
        mAdapter_interests.notifyDataSetChanged();
        mAdapter_setMeal.notifyDataSetChanged();
    }


    private void setRecyclerViewBook() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
        mRecyclerViewBook.setLayoutManager(linearLayoutManager);
        mRecyclerViewBook.addItemDecoration(new SpacesItemDecoration(6));
        mData_book = new ArrayList<>();
        mAdapter_book = new H5TestBookAdapter(mData_book);
        mRecyclerViewBook.setAdapter(mAdapter_book);
    }

    private void setRecyclerViewSetMeal() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(RecyclerView.HORIZONTAL);
        mRecyclerViewSetMeal.setLayoutManager(linearLayoutManager);
        mRecyclerViewSetMeal.addItemDecoration(new SpacesItemDecoration(6));
        mData_setMeal = new ArrayList<>();
        mAdapter_setMeal = new H5TestSetMealAdapter(mData_setMeal);
        mRecyclerViewSetMeal.setAdapter(mAdapter_setMeal);
        mAdapter_setMeal.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (BeanSetMeal meal : mData_setMeal) {
                    meal.select = false;
                }
                BeanSetMeal setMeal = mData_setMeal.get(position);
                setMeal.select = true;
                mData_setMeal.set(position, setMeal);
                mAdapter_setMeal.notifyDataSetChanged();
//                BeanSetMeal beanSetMeal = (BeanSetMeal) adapter.getData().get(position);
                switch (setMeal.type){
                    case "连续包年":
                        tvExplanation.setText("说明：到期自动续费12个月，可随时取消。");
                        tvExplanation.setVisibility(View.VISIBLE);
                        break;
                    case "连续包季":
                        tvExplanation.setText("说明：到期自动续费3个月，可随时取消。");
                        tvExplanation.setVisibility(View.VISIBLE);
                        break;
                    case "连续包月":
                        tvExplanation.setText("说明：到期自动续费1个月，可随时取消。");
                        tvExplanation.setVisibility(View.VISIBLE);
                        break;
                    default:
                        tvExplanation.setVisibility(View.GONE);
                        break;

                }

            }
        });
    }

    private void setScrollView() {

        mScrollView.post(new Runnable() {
            @Override
            public void run() {
                //滚动到指定位置（滚动要跳过的控件的高度的距离）
//                mScrollView.scrollTo(0, llNeedToSkip.getMeasuredHeight());
                //如果要平滑滚动，可以这样写
                //scrollView.smoothScrollTo(0, llNeedToSkip.getMeasuredHeight());
                mScrollView.smoothScrollTo(0, conBg2.getTop());
            }
        });
    }

    @OnClick({R.id.iv_close, R.id.tv_more})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_close:
                break;
            case R.id.tv_more:
                setScrollView();
                break;
        }
    }
}
